package com.joymart.qualification.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.joymart.common.model.Range;
import com.joymart.user.model.BusinessRole;
import com.joymart.user.model.CachedUser;
import lombok.Data;
import org.springframework.data.annotation.Transient;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 批发商和代理的保级评估
 */
@Data
public class WhsAgentRetainEvaluation extends RetainEvaluation {

    private String id;
    private String userId;
    @Transient
    @JsonIgnore
    private CachedUser evaluateUser;
    private BusinessRole targetRole;
    // 评估依据区间
    private Range range;
    private List<MonthlyStats> monthlyStatsList;

    @Override
    public boolean isPassed(){
        if(monthlyStatsList.isEmpty()){
            return false;
        }
        //达标月份数达到一半就可以保级，向下取整
        return  monthlyStatsList.stream().filter(MonthlyStats::isPassed).count() >= (monthlyStatsList.size()/2)  ;
    }


    @Data
    public static class MonthlyStats {
        private LocalDateTime month;
        private BigDecimal groupPvSpec;
        private BigDecimal groupPv;

        public boolean isPassed(){
           return this.groupPv.compareTo(groupPvSpec) >=0;
        }
    }


}
